<?php


namespace App\Api\Services;


use App\Api\Models\LiveAnchor;
use App\Models\Live\CmcLiveAnchor;
use App\Models\Live\CmcLiveStudio;

class Live
{
    /**
     * cuiqun
     * 根据传过来的顺序规则进行排序
     * @param string $order
     * @param string $order_line
     *
     */
    static public function serGetList($order = 'desc',$order_line='created_at'){
        $data = \App\Api\Models\Live::getList($order,$order_line);
        if (empty($data)) return [];
        return $data;
    }

    /**
     * cuiqun
     * 根据主播id查询一条数据
     * @param $id
     * @return array
     */
    static public function getStudio($id){
        $data = \App\Api\Models\Live::getAnchorOnce($id);
        if (empty($data)) return [];
        return $data;
    }

    /**
     * cuiqun
     * 查询该主播下的回放地址
     * @param $id
     */
    static public function getPlayBack($id){
        $playBack = \App\Api\Models\Live::getPlayBack($id);
        if (!$playBack) return [];
        return $playBack;
    }

    /**
     * cuiqun
     * 获取单条回放地址
     * @param $id
     * @return array
     */
    static public function playBackOnce($id){
        $data = \App\Api\Models\Live::getAnchorOnce($id);
        if (empty($data)) return [];
        return $data;
    }
    /**
     * cuiqun
     * 关闭直播
     * @param $data
     * @return array|bool
     */
    static public function LiveOver($id){
        $id = LiveAnchor::anchorInfo($id);
        $live = LiveAnchor::where('id',$id)->get('is_play')->toArray()[0]['is_play'] - 1;
        return LiveAnchor::where('id',$id)->update(['is_play'=>$live]);
    }
}